home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / nrpas13.zip / TRAPZD.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  654b  |  29 lines

  1. PROCEDURE trapzd(a,b: real; VAR s: real; n: integer);
  2. (* Programs calling TRAPZD must provide a function
  3. func(x:real):real which is to be integrated. They must
  4. also define the variable
  5. VAR
  6.    glit: integer;
  7. in the main routine. *)
  8. VAR
  9.    j: integer;
  10.    x,tnm,sum,del: real;
  11. BEGIN
  12.    IF (n = 1) THEN BEGIN
  13.       s := 0.5*(b-a)*(func(a)+func(b));
  14.       glit := 1
  15.    END
  16.    ELSE BEGIN
  17.       tnm := glit;
  18.       del := (b-a)/tnm;
  19.       x := a+0.5*del;
  20.       sum := 0.0;
  21.       FOR j := 1 TO glit DO BEGIN
  22.          sum := sum+func(x);
  23.          x := x+del
  24.       END;
  25.       s := 0.5*(s+(b-a)*sum/tnm);
  26.       glit := 2*glit
  27.    END
  28. END;
  29.